<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="12">
            <a-form-model-item label="含税金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="amount">
              <a-input-number
                :disabled="formDisabled"
                :max="999999999"
                :precision="2"
                v-model="model.amount"
                placeholder="请输入含税金额"
                :min="model.invoicingAmount"
                @blur="amountBlur"
                style="width: 100%" />
                <span v-if="model.invoicingAmount" style="color: red;margin: 0">
                <span> 当前款项已开票{{ model.invoicingAmount }}元, 金额调整不可低于开票金额</span>
              </span>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="税率(%)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taxRate">
                <j-dict-select-tag
                  disabled
                  type="list"
                  v-model="model.taxRate"
                  dictCode="contract_rate_type"
                  placeholder="请选择税率"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="税额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taxation">
              <a-input-number
                disabled
                :max="999999999"
                :min="0"
                :precision="2"
                v-model="model.taxation"
                placeholder="请输入税额"
                style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="未税金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="untaxedAmount">
              <a-input-number
                disabled
                :max="999999999"
                :min="0"
                :precision="2"
                v-model="model.untaxedAmount"
                placeholder="请输入未税金额"
                style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-textarea :disabled="formDisabled" :max-length="200" v-model="model.remark" rows="4" placeholder="请输入备注"/>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { getAction } from '@/api/manage'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
  import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
  import SelectCustomerInput from '@/views/scy/components/SelectCustomerInput'
  import moment from 'moment'
  import { mapGetters } from 'vuex'
  import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'
  export default {
    name: 'ErpOmcContractTaxRateInfoList',
    components: {
      SelectUserByDep,
      SelectTeamInput,
      SelectCompanyInput,
      SelectCustomerInput
    },
    props: {
      // 表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      },
      contractId: {
        type: String,
        default: '',
        required: false
      },
      projectId: {
        type: String,
        default: '',
        required: false
      },
      managementTeam: {
        type: String,
        default: '',
        required: false
      },
      undertaker: {
        type: String,
        default: '',
        required: false
      }
    },
    data () {
      return {
        model: {},
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 }
        },
        confirmLoading: false,
        validatorRules: {
          amount: [
            { required: true, message: '请输入含税金额!' }
          ],
        },
        url: {
          add: '/api/erp/audit/paybackDisclaimer/paybackDisclaimerDisclaimerInfo/add',
          edit: '/api/erp/audit/paybackDisclaimer/paybackDisclaimerDisclaimerInfo/edit',
          queryById: '/api/erp/audit/paybackDisclaimer/paybackDisclaimerDisclaimerInfo/queryById',
          queryPaymentNode: '/api/erp/progress/erpProgressPaymentNode/queryListByContractId',
          queryProjectTaskFinal: '/api/erp/omc/project/erpOmcProjectTaskFinal/queryPageList' // 任务档案-用于查询项目负责人列表
        },
        paymentNameList: [],
        exemptionProjectHeadList: [],
        flag: false,
        dictOptions: {}
      }
    },
    computed: {
      formDisabled() {
        return this.disabled
      }
    },
    created () {
       // 备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    mounted() {

    },
    methods: {
      ...mapGetters(['userInfo']),
      moment,
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.$refs.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      // 填写含税金额
      amountBlur () {
        // 计算税额(元) 未税金额(元)
        this.model.taxation = ((this.model.amount / (1 + Number(this.model.taxRate) / 100)) * (Number(this.model.taxRate) / 100)).toFixed(2); // 税额
        this.model.untaxedAmount = (this.model.amount - this.model.taxation).toFixed(2); // 未税金额;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            let data = JSON.stringify(that.model)
            that.$emit('ok', JSON.parse(data), this.flag);
          } else {
            that.$emit('unButtonDisable');
          }
        })
      }
    }
  }
</script>
